package com.erlang.spring.factory;

import com.erlang.spring.pojo.Car;

/**
 * @Description：汽车工厂
 */
public class CarFactroy {

    /**
     * @Description 根据class对象实例化车
     * @param carClass 车辆class对象
     * @return
     */
    public static Car getCar(Class<?> carClass){
        String carClassName = carClass.getName();
        Car car =null;
        try {
            car = (Car) Class.forName(carClassName).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return car;
    }

    /**
     * @Description 根据class对象实例化车
     * @param carClassName 车辆class对象全限定名称
     * @return
     */
    public static Car getCar(String carClassName ){
        Car car =null;
        try {
            car = (Car) Class.forName(carClassName).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return car;
    }
}